package com.yanqu.road.entity.activity.ruishou;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

/**
 * 地区数据
 */
@FieldTypeAnnotation(tableName = "t_u_activity_rui_shou_area_data")
public class RuiShouAreaData extends DataObject {

    @FieldTypeAnnotation(desc = "活动ID", select = true, update = true)
    private int activityId;

    @FieldTypeAnnotation(desc = "用户ID", select = true, update = true)
    private long userId;

    @FieldTypeAnnotation(desc = "地区ID", select = true, update = true)
    private int areaId;

    @FieldTypeAnnotation(desc = "出战的怪物数据   位置->怪物")
    private Map<Integer, RuiShouFightMonsterData> fightMonsterDataMap = new HashMap<>();

    @FieldTypeAnnotation(desc = "是否可重置 初始false")
    private boolean reset;

    @FieldTypeAnnotation(desc = "是否锁定奖励")
    private boolean lockReward;

    @FieldTypeAnnotation(desc = "怪物信息")
    private Map<Integer, RuiShouMonsterData> monsterDataMap = new HashMap<>();

    @FieldTypeAnnotation(desc = "表现池")
    private LinkedList<Integer> actionIdPool = new LinkedList<>();


    public RuiShouAreaData() {

    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setUpdateOption();
        }
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            setUpdateOption();
        }
    }

    public int getAreaId() {
        return areaId;
    }

    public void setAreaId(int areaId) {
        if (this.areaId != areaId) {
            this.areaId = areaId;
            setUpdateOption();
        }
    }
    public Map<Integer, RuiShouFightMonsterData> getFightMonsterDataMap() {
        return fightMonsterDataMap;
    }

    public void setFightMonsterDataMap(Map<Integer, RuiShouFightMonsterData> fightMonsterDataMap) {
        if (fightMonsterDataMap == null) {
            return;
        }
        this.fightMonsterDataMap = fightMonsterDataMap;
        setUpdateOption();
    }

    public boolean isReset() {
        return reset;
    }

    public void setReset(boolean reset) {
        if (this.reset != reset) {
            this.reset = reset;
            setUpdateOption();
        }
    }

    public boolean isLockReward() {
        return lockReward;
    }

    public void setLockReward(boolean lockReward) {
        if (this.lockReward != lockReward) {
            this.lockReward = lockReward;
            setUpdateOption();
        }
    }

    public int getChooseAwardCnt(int monsterId, int rewardId) {
        if (!monsterDataMap.containsKey(monsterId)) {
            return 0;
        }
        return monsterDataMap.get(monsterId).getChooseAwardCntMap().getOrDefault(rewardId, 0);
    }

    /**
     * 增加计数
     *
     * @param monsterId 怪物id
     * @param rewardId  奖励id
     */
    public void addChooseAwardCnt(int monsterId, int rewardId) {
        if (!monsterDataMap.containsKey(monsterId)) {
            RuiShouMonsterData monsterData = new RuiShouMonsterData(monsterId);
            monsterDataMap.put(monsterId, monsterData);
        }
        RuiShouMonsterData monsterData = monsterDataMap.get(monsterId);
        monsterData.getChooseAwardCntMap().put(rewardId, monsterData.getChooseAwardCntMap().getOrDefault(rewardId, 0) + 1);
        setUpdateOption();
    }

    /**
     * 增加出战次数
     *
     * @param monsterId 怪物id
     */
    public void addMonsterFightCnt(int monsterId) {
        if (!monsterDataMap.containsKey(monsterId)) {
            RuiShouMonsterData monsterData = new RuiShouMonsterData(monsterId);
            monsterDataMap.put(monsterId, monsterData);
        }
        RuiShouMonsterData monsterData = monsterDataMap.get(monsterId);
        monsterData.setFightCnt(monsterData.getFightCnt() + 1);
        setUpdateOption();
    }

    /**
     * 怪物出战次数
     * @param monsterId
     * @return
     */
    public int getMonsterFightCnt(int monsterId) {
        if (!monsterDataMap.containsKey(monsterId)) {
            return 0;
        }
        return monsterDataMap.get(monsterId).getFightCnt();
    }

    public LinkedList<Integer> getActionIdPool() {
        return actionIdPool;
    }

    public void setActionIdPool(LinkedList<Integer> actionIdPool) {
        if (actionIdPool == null) {
            return;
        }
        this.actionIdPool = actionIdPool;
        setUpdateOption();
    }

    public Map<Integer, RuiShouMonsterData> getMonsterDataMap() {
        return monsterDataMap;
    }

    public void setMonsterDataMap(Map<Integer, RuiShouMonsterData> monsterDataMap) {
        if (monsterDataMap == null) {
            return;
        }
        this.monsterDataMap = monsterDataMap;
        setUpdateOption();
    }

    public void monsterIncrementCnt(int monsterId) {
        if (!monsterDataMap.containsKey(monsterId)) {
            RuiShouMonsterData monsterData = new RuiShouMonsterData(monsterId);
            monsterDataMap.put(monsterId, monsterData);
        }
        RuiShouMonsterData monsterData = monsterDataMap.get(monsterId);
        monsterData.setIncrementCnt(monsterData.getIncrementCnt() + 1);
        setUpdateOption();
    }

    public void resetMonsterIncrementCnt(int monsterId) {
        if (!monsterDataMap.containsKey(monsterId)) {
            RuiShouMonsterData monsterData = new RuiShouMonsterData(monsterId);
            monsterDataMap.put(monsterId, monsterData);
        }
        RuiShouMonsterData monsterData = monsterDataMap.get(monsterId);
        monsterData.setIncrementCnt(0);
        setUpdateOption();
    }

    /**
     * 获取自选
     * @param monsterId
     * @return
     */
    public int getChooseRewardId(int monsterId) {
        if (!monsterDataMap.containsKey(monsterId)) {
            RuiShouMonsterData monsterData = new RuiShouMonsterData(monsterId);
            monsterDataMap.put(monsterId, monsterData);
        }
        return monsterDataMap.get(monsterId).getChooseRewardId();
    }

    public int getIncrementCnt(int monsterId) {
        if (!monsterDataMap.containsKey(monsterId)) {
            return 0;
        }
        return monsterDataMap.get(monsterId).getIncrementCnt();
    }

    /**
     * 清除自选奖励
     */
    public void clearChooseRewardId() {
        for (RuiShouMonsterData monsterData : monsterDataMap.values()) {
            monsterData.setChooseRewardId(0);
        }
        setUpdateOption();
    }

    /**
     * 设置自选奖励id
     * @param monsterId
     * @param rewardId
     */
    public void setChooseRewardId(int monsterId, int rewardId) {
        if (!monsterDataMap.containsKey(monsterId)) {
            RuiShouMonsterData monsterData = new RuiShouMonsterData(monsterId);
            monsterDataMap.put(monsterId, monsterData);
        }
        RuiShouMonsterData monsterData = monsterDataMap.get(monsterId);
        monsterData.setChooseRewardId(rewardId);
    }
}
